package configuration

import (
	"encoding/json"
	"errors"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

func init() {

	var err error
	var b = client.Load("MaidTemplate")
	if err = json.Unmarshal(b, &MaidConfigs); err != nil {
		panic(err)
	}

	log.Info("Load MaidTemplate.json success.")

	//********************************************************************//

	//********************************************************************//

	b = client.Load("MaidPeerage")
	if err = json.Unmarshal(b, &MaidClassConfigs); err != nil {
		panic(err)
	}

	log.Info("Load MaidPeerage.json success.")
}

type (
	// 侍女配置
	MaidConfig struct {
		MaidID          int32   `json:"ID"` // 侍女ID
		DateID          int32   // 约会ID
		Name            string  // 侍女名称
		DefaultIntimacy int32   // 初始侍女亲密度
		DefaultCharm    int32   // 初始侍女魅力
		Skills          []int32 // 技能ID
		NeedFavour      int32   // 好感度
	}

	// 爵位
	MaidClassConfig struct {
		ID           int32   // 封位ID
		Quality      int32   // 封位品质
		CountMax     int32   // 限制数量
		NeedIntimacy int32   // 侍女亲密度要求
		NeedCharm    int32   // 侍女魅力要求
		AttributeID  int32   // 属性ID
		AwakeRate    float32 // 觉醒概率+成
	}
)

var (
	MaidConfigs      = map[int32]MaidConfig{}
	MaidClassConfigs = map[int32]MaidClassConfig{}
)

func GetByMaidID(ID int32) (MaidConfig, error) {

	var conf, ok = MaidConfigs[ID]
	if ok {
		return conf, nil
	}

	return MaidConfig{}, errors.New(fmt.Sprintf("MaidID not found [%d]", ID))
}

func GetByMaidClass(class int32) (MaidClassConfig, error) {

	var conf, ok = MaidClassConfigs[class]
	if ok {
		return conf, nil
	}

	return MaidClassConfig{}, errors.New(fmt.Sprintf("MaidClass not found [%d]", class))
}
